//
//  ViewController.m
//  截屏实现
//
//  Created by hyl on 16/6/27.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //实现屏幕截图的步骤
    //开启一个图片上下文
    UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0);
    //获得上下文
    CGContextRef context=UIGraphicsGetCurrentContext();
    //将屏幕layer渲染到上下文
    [self.view.layer renderInContext:context];
    //获取图
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    //关闭上下文
    NSData *data=UIImageJPEGRepresentation(image, 1);
    [data writeToFile:@"/Users/hyl/Desktop/素材/view.jpg" atomically:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
